const fs = require('fs');
const {getURCSource,getURCOutput}=require('../../config/index');
const {APP_ID} = require('../../config/index');

const IMG_SUFFIX = ['png', 'jpeg', 'jpg', 'bmp']



function readSourceSync() {
    const sourceFiles = fs.readdirSync(getURCSource())
    const outputFiles = fs.readdirSync(getURCOutput())
    const outputFilesSuffix = outputFiles.map(file => file.split('.')[0])

    // 过滤非图片
    const files = sourceFiles.filter(file => {
        const [fileName, suffixName] = file.split('.')
        return IMG_SUFFIX.includes(suffixName.toLowerCase()) && !outputFilesSuffix.includes(fileName)
    })
    return files.map(file => getURCSource()+file)
}

function getPostParmas(extname,imgBase64){
    return {
        "header": {
          "app_id": APP_ID,
          "status": 3
        },
        "parameter": {
          "sf8e6aca1": {
            "category": "ch_en_public_cloud",
            "result": {
              "encoding": "utf8",
              "compress": "raw",
              "format": "json"
            }
          }
        },
        "payload": {
          "sf8e6aca1_data_1": {
            "encoding": extname,
            "status": 3,
            "image": imgBase64
          }
        }
      }
}
module.exports = {
    readSourceSync,
    getPostParmas
}